package com.zhh.controller;


import com.zhh.common.ServerResponse;
import com.zhh.dto.FacilityDto;
import com.zhh.service.FacilityLeaseService;
import com.zhh.service.FacilityService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;



@RestController
public class FacilityController {

    final static Logger log = LoggerFactory.getLogger(FacilityController.class);

    @Autowired
    private FacilityService facilityService;
    @Autowired
    private FacilityLeaseService leaseService;


    /**
     * 录入设备
     */
    @RequiresPermissions("/facility/register")
    @RequestMapping(value = "/facility/register", method = RequestMethod.POST)
    public ServerResponse register(FacilityDto facilityDto) {
        log.info("录入设备");
        return facilityService.insert(facilityDto);
    }

    /**
     * 领取物资
     */
    @RequiresPermissions("/facility/take")
    @RequestMapping(value = "/facility/take", method = RequestMethod.POST)
    public ServerResponse take(String suid) {
        log.info("领取设备");
        return leaseService.insert(suid);
    }
    /**
     * 归还物资
     */
    @RequestMapping(value = "/facility/return", method = RequestMethod.POST)
    public ServerResponse returnFacility(String suid) {
        log.info("归还设备");
        return leaseService.returnFacility(suid);
    }

    /**
     * 归还物资
     */
    @RequestMapping(value = "/facility/storge", method = RequestMethod.POST)
    public ServerResponse storge(String suid) {
        log.info("设备入库");
        return leaseService.returnFacility(suid);
    }

}
